<!--
 * @name: 
 * @version: 1.1.1
 * @Author: 刘大可
 * @Date: 2022-10-26 18:15:22
 * @LastEditors: 刘大可
 * @LastEditTime: 2022-11-29 17:39:58
-->
<template>
    <view style="background:#F9FAFB;" >
        <view class="headers" :style="{'margin-top':'-'+top+'px','padding-top':top+'px'}">
            <view class="search row" @click="go('/gc_school/pages/canteen/list')">
                店铺名称/美食名称
                <view class="cuIcon-search"></view>
            </view>
                <swiper class="banner margin-lr" :class="rank_show?'':'margin-top'" :autoplay="true" :current="current"
                    v-if="schoolInfo.slide.length>0">
                    <block v-if="schoolInfo.slide.length > 0">
                        <block v-for="(item, index) in schoolInfo.slide" :key="index">
                            <swiper-item>
                                <block v-if="item.img">
                                    <image :src="item.img" mode="widthFix" @tap="slideJump" :data-url="item.url"
                                        :data-type="item.url_type"></image>
                                </block>
                                <block v-else>
                                    <image src="/static/images/banners.jpg" mode="widthFix"></image>
                                </block>
                            </swiper-item>
                        </block>
                    </block>
                    <block v-else>
                        <swiper-item>
                            <image src="/static/images/banners.jpg" mode="widthFix"></image>
                        </swiper-item>
                    </block>
                </swiper>
        </view>
        <view class="navs">
            <school-store-classify></school-store-classify>
        </view>
        <view class="tipss">
            <uni-notice-bar @click="go('/gc_school/pages/notice/notice?id='+schoolInfo.notice[0].id)" background-color="#fff"
                color="#000" v-if="schoolInfo.notice.length>0" class="margin-lr tips" show-icon scrollable
                :text="schoolInfo.notice[0].title" />
        </view>
        <view class="hart_store" v-if="hart.length>0">
            <view class="tit row">
                <view class="cuIcon-hotfill cuIcon"></view>
                点餐热榜
                <view class="sub_tit">
                    | 看看他们在吃什么
                </view>
            </view>
            <view class="hart_list row">
                <block v-for="(item,index) in hart" :key="index">
                    <view class="hart_item"  @click="goStore('/gc_school/pages/foold/foold?id=' + item.business_id)">
                        <image
                            class="main_img"
                            :src="item.goods.goods_img"
                            mode="scaleToFill"
                        />
                        <view class="title">{{item.goods.goods_name}}</view>
                    </view>
                
                </block>
            </view>
        </view>
        <view class="topp" :style="{'top':top+'px'}">

            <view class="cates row">
                <block v-for="(item,index) in list" :key="index">
                    <view class="cate col" :class="flg==index?'cur':''" @click="tagetCate(item.type_id,index)">
                        {{item.type_name}}
                        <!-- {{item.type_id}} -->
                    </view>
                </block>
            </view>
        </view>
        <view class="store_list">
            <block v-for="(item,index) in  goods" :key="index">
                <view class="store_item"   @click="goStore('/gc_school/pages/foold/foold?id=' + item.business_id)">
                    <view class="store_info row">
                        <image
                            class="main_img"
                            :src="item.business_image"
                            mode="scaleToFill"
                            
                        />
                        <view class="info">
                            <view class="name row">
                               {{item.business_name}}
                                <view class="tag row tag2" v-if="item.is_dormitory_store==1">
                                  宿舍小店
                                </view>
                                <view class="tag row" :class="item.type != 1?'tag1':'tag2'" v-else>
                                    {{item.type != 1? "校外":"校内"}}
                                </view>
                            </view>
                            <view class="date">营业时间：{{item.timeslot}}</view>
                            <view class="date">已售{{item.sale_num}}份 ¥{{item.service_price}}起送</view>
                        </view>
                    </view>
                    <view class="goods_list row" v-if="item.goods.length>0">
                        <block v-for="(gitem,gindex) in item.goods" :key="gindex">
                            <view class="goods_item">
                                <image class="main_img" :src="gitem.goods_img" mode="scaleToFill" />
                                <view class="title">{{gitem.goods_name}}</view>
                                <view class="price">￥{{gitem.price}}</view>
                            </view>
                        
                        </block>
                        
                    </view>
                </view>
            </block>
            <view class="all col" @click="nextPage">
                {{ content }}
            </view>
        </view>

       
    </view>
</template>
<script>
var app = getApp();
export default {
    data() {
        return {
            list:[],
            flg:0,
            hart:[],
            page:1,
            goods:[],
            content:"查看更多"
        }
    },
    props: {
       top: {
            type: String,
            default() {
                return "";
            }
        },
        schoolInfo:{
            type:Object,
            default() {
                return {
                    
                };
            }
        }

    },
    created(){
        this.initData()
        this.getHart()
    },
    methods: {
        goStore(e) {
            // try {
            //     uni.setStorageSync('module_id', this.schoolInfo.default_store_module.id)
            // } catch (error) {

            // }
            this.go(e)
        },
        tagetCate(type_id, index){
            this.flg=index
            this.getStore(type_id)

        },
        async initData() {
            var that = this;
            var shcool_id = uni.getStorageSync('schoolId');
            app.globalData.util.request({
                url: 'ZhBusinesType/index',
                method: 'GET',
                data: {
                    s_id: shcool_id,
                   
                },
                success(res) {
                    if (res.data.status == 200) {
                        that.list = [
                            ...res.data.data.list,
                        ]
                        if (res.data.data.list.length > 0) {
                            // that.getStore();
                        }
                        console.log(that.list);
                    }
                }
            });

        },
        getHart(){
            var that = this;
            var shcool_id = uni.getStorageSync('schoolId');
            app.globalData.util.request({
                url: 'ZhGoods/getcommodity',
                method: 'GET',
                data: {
                    s_id: shcool_id,
                    // page: 1,
                    // limit:10,
                },
                success(res) {
                    console.log(res);
                    if (res.data.status == 200) {
                        that.hart = [
                            ...res.data.data
                        ]
                        // if (res.data.data.list.length > 0) {
                        //     // that.getStore();
                        // }
                       that.getStore(res.data.data[0].type_id)
                        console.log(that.hart);
                    }
                }
            });


            // /api/?wxapp_id=3&s_id=8
        },
        nextPage(){
            this.page+=1
            let type_id = this.list[this.flg].type_id
            this.getStore(type_id)

        },
        async getStore(type_id = "") {
            var that = this;
            uni.showLoading({
                title: '加载中'
            });

            app.globalData.util.request({
                url: 'ZhBusinesType/getBusiness',
                method: 'GET',
                data: {
                    latitude: uni.getStorageSync('latitude'),
                    longitude: uni.getStorageSync('longitude'),
                    type_id: type_id,
                    page: that.page,
                    s_id: uni.getStorageSync('schoolId'),
                    kwd: "",
                    limit: 10
                },

                success:(res)=> {
                    uni.hideLoading();
                    if (res.data.status == 200) {
                        if (res.data.data.data.length) {
                            this.goods = this.page == 1 ? res.data.data.data : [
                                ...this.goods,
                                ...res.data.data.data
                            ]
                            return
                        }
                        this.content = "没有更多了~"
                        this.tips.tips(this.content)

                       
                    }
                }
            });
        },
    },
}
</script>
<style lang="scss">
    @import "./main.scss";
</style>